import Vue from 'vue'
import VueRouter from 'vue-router'

const Home=()=>import('views/home/Home')
const Category=()=>import('views/category/Category')
const Cart=()=>import('views/cart/Cart')
const Profile=()=>import('views/profile/Profile')
const Detail=()=>import('views/detail/Detail')

const originalPush = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes= [
    {
      path:"",
      redirect: "/home"
    },
    {
      path:'/home',
      component:Home
    },
    {
      path:'/Category',
      component:Category
    },
    {
      path:'/cart',
      component:Cart
    },
    {
      path:"/profile",
      component:Profile
    },
    {
      path:"/detail",
      component:Detail
    }
  ]
/* 使用html中history模式 ，在详情页跳转是必须使用查询字符串模式传参（query）*/
/* .params 传参 存在的问题： 页面刷新或者回退传递的参数会丢失配合/xxx/:name使用 */
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
export default router
